package com.geng.io.bio;

import java.io.*;
import java.net.Socket;

/**
 * bio client
 */
public class BIOclient {
    public static void main(String[] args) throws IOException {
        int port = 8072;
        String serverIp = "127.0.0.1";
        Socket socket = null;
        BufferedReader reader = null;
        BufferedWriter writer = null;

        try{
            socket = new Socket(serverIp,port);
            reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            writer.write("hello BIO .\n");
            writer.flush();

            String echo = reader.readLine();
            System.out.println(echo);
        }finally {
            if(reader != null){
                try{
                    reader.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
            if(socket != null){
                try{
                    socket.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }


    }
}
